package com.thiswhyme.fsplus.sentinel.feign.instancefilter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @description: 自定义降级配置
 * 针对实例级别资源，发生熔断时，从负载均衡中剔除该实例（剔除时间为配置的窗口时间）
 * @author: thiswhyme
 * @date: 2021/4/30
 */
@ConditionalOnProperty(name = "feign.sentinel.fsplus.instance-filter-enabled", havingValue = "true")
public class InstanceFilterDegradeConfig {

    @Bean
    @ConditionalOnMissingBean(BlockServerContext.class)
    public BlockServerContext blockServerContext() {
        return new BlockServerContext();
    }

    @Bean
    @ConditionalOnMissingBean(CustomZoneAvoidanceRule.class)
    public CustomZoneAvoidanceRule customZoneAvoidanceRule(BlockServerContext blockServerContext) {
        return new CustomZoneAvoidanceRule(blockServerContext);
    }
}
